package com.xu.rule;

import com.alibaba.csp.sentinel.init.InitFunc;
import com.alibaba.csp.sentinel.slots.block.RuleConstant;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager;
import com.google.common.collect.Lists;

import java.util.List;

/**
 *
 * 手动配置流控规则 （也可在sentinel页面进行流控配置）
 *
 * @author xudenghui
 * @create 2021-12-30 16:04
 **/
public class FlowFuleInitFunc implements InitFunc {

    @Override
    public void init() throws Exception {
        List<FlowRule> ruleList  = Lists.newArrayList();
        FlowRule rule = new FlowRule();
        rule.setCount(1);
        rule.setResource("hello");
        rule.setGrade(RuleConstant.FLOW_GRADE_QPS);
        rule.setLimitApp("default");
        ruleList.add(rule);
        FlowRuleManager.loadRules(ruleList);
    }
}
